package cn.itsource.org.service.impl;

import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.Logininfo;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.mapper.ShopMapper;
import cn.itsource.org.myenum.ShopState;
import cn.itsource.org.service.ILogininfoService;
import cn.itsource.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 业务实现类：
 */
@Service
public class LogininfoServiceImpl extends BaseServiceImpl<Logininfo> implements ILogininfoService {
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public String active(Long id) {
        //去查询数据库  看有没有这条数据
        Logininfo byId = super.findById(id);
        if(byId.getDisable()){
            return "该账号已激活！！！！";
        }
        //有就修改
        if(byId == null){
            return "请不要搞事情！！！！！";
        }
        byId.setDisable(true);
        super.update(byId);
        //没有 返回一个提示
        Employee byLoginInfoId = employeeMapper.findByLoginInfoId(id);
        Shop shop = shopMapper.findById(byLoginInfoId.getShop_id());
        shop.setState(ShopState.THREE.getCode());
        shopMapper.update(shop);
        return "激活成功";
    }
}
